//
//  NCPTopImageBtn.m
//  西楚网
//
//  Created by 徐汉卿 on 16/6/20.
//  Copyright © 2016年 徐汉卿. All rights reserved.
//

#import "NCPTopImageBtn.h"

@implementation NCPTopImageBtn

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/


-(instancetype)init{
    if (self  = [super init]) {
        self.scale = 1;
        self.scaleImageView = 0.7;
        self.titleLabel.adjustsFontSizeToFitWidth = YES;
        self.imageView.contentMode =    UIViewContentModeCenter;
//UIViewContentModeCenter
//        self.imageView.contentMode =    UIViewContentModeScaleAspectFit;
        
        
        
        
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
//        self.adjustsImageWhenDisabled = NO;
        self.adjustsImageWhenHighlighted = NO;
        [self setTitleColor:[UIColor darkGrayColor] forState:0];
    }
    return self;
}



-(CGRect)imageRectForContentRect:(CGRect)contentRect
{
    

    CGRect contentRectNew = CGRectMake(contentRect.size.width * (1-self.scale)/2.0, contentRect.size.height * (1-self.scale)/2.0, contentRect.size.width * self.scale, contentRect.size.height * self.scale);
    return CGRectMake(contentRectNew.origin.x, contentRectNew.origin.y, contentRectNew.size.width, contentRectNew.size.height * self.scaleImageView);
}


-(CGRect)titleRectForContentRect:(CGRect)contentRect
{
     CGRect contentRectNew = CGRectMake(contentRect.size.width * (1-self.scale)/2.0, contentRect.size.height * (1-self.scale)/2.0, contentRect.size.width * self.scale, contentRect.size.height * self.scale);
    return CGRectMake(contentRectNew.origin.x, contentRectNew.size.height * 0.7 + contentRectNew.origin.y, contentRectNew.size.width, contentRectNew.size.height * (1- 0.7));
}
@end
